/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package encapsfo;

import encapsfo.EmrBands.EmrBand;
import encapsfo.EmrBands.EmrBand.EmrRects;
import encapsfo.EmrRect.EmrText;
import encapsfo.EmrRect.EmrText.EmrInline;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
 *
 * @author rejun001
 */
public class TestJAXBContext {
    public static void main(String args[]) {

        TestJAXBContext tjc = new TestJAXBContext();
        try {
            JAXBContext jc = JAXBContext.newInstance("encapsfo");
            Unmarshaller um = jc.createUnmarshaller();
            EmrBands emrBands = (EmrBands) um.unmarshal(new File("ENCAPSULATED_SFO05.xml"));
            
            Marshaller m = jc.createMarshaller();
            
            List<EmrBand> ebs = emrBands.getEmrBand();
            Iterator ebit = ebs.iterator();
            while (ebit.hasNext()) {
                EmrBand eb = (EmrBand) ebit.next();
                System.out.println("EmrBand: pageBreakKind = " + eb.getPageBreakKind() );
                List<EmrRects> ers = eb.getEmrRects();
                Iterator ersit = ers.iterator();
                while (ersit.hasNext()) {
                    EmrRects erects = (EmrRects) ersit.next();
                    System.out.println("EmrRects: contentType = " + erects.getContentType());
                }
                List<EmrRect> erlist = eb.getEmrRect();
                Iterator<EmrRect> erit = erlist.iterator();
                while (erit.hasNext()) {
                    EmrRect er = (EmrRect) erit.next();
                    System.out.println("EmrRect: cell-containership= " + er.getCellContainership() + ", content-type = " + er.getContentType() +
                            ", content-name = " + er.getContentName());
                }
                tjc.displayChildRects(erlist);
            }
            
            
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public boolean displayChildRects(List<EmrRect> ers) {
        if (ers == null) {
            return false;
        }
        Iterator it = ers.iterator();
        List<EmrRect> emrKids = null;
        List<EmrText> ets;
        int rinx = 0;
        while (it.hasNext()) {
            EmrRect er = (EmrRect) it.next();
            System.out.print(rinx + "\temr-rect: stacking: " + er.getStacking());
            System.out.print(", bgColor: " + er.getBackgroundColor());
            System.out.print(", font-fam: " + er.getFontFamily());
            System.out.print(", height: " + er.getHeight());
            System.out.print(", width: " + er.getWidth());
            System.out.println(", content-name: " + er.getContentName());
            System.out.print("\t");
            
            ets = er.getEmrText();
            Iterator etIt = ets.iterator();
            int tinx = 0;
            while (etIt.hasNext()) {
                
                EmrText et = (EmrText) etIt.next();
                System.out.println(tinx + "emr-text: font size: " + et.getFontSize());
                List<EmrInline> els = et.getEmrInline();
                Iterator elIt = els.iterator();
                int einx = 0;
                while (elIt.hasNext()) {
                    
                    EmrInline el = (EmrInline) elIt.next();
                    System.out.print("\t" + einx + "\temr-inline: Font Size" + el.getFontSize());
                    System.out.println(", VALUE: " + el.getValue());
                    einx++;
                }
                tinx++;
            }
            emrKids = er.getEmrRect();
            displayChildRects(emrKids); 
            rinx++;
        } 
        return true;
    }
}
